#include "SWindow.h"


SWindows*		g_pWindow = 0;
LRESULT WINAPI gMsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	return g_pWindow->WindowMsgProc( hWnd, msg, wParam, lParam );
}

LRESULT SWindows::WindowMsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	switch( msg )
	{
	case WM_ACTIVATEAPP :
		{
			m_IsActive = (BOOL)wParam;
		}break;
	case WM_DESTROY :
		m_IsActive = FALSE;
		PostQuitMessage(0);
		break;
	case WM_CLOSE :
		m_IsActive = FALSE;
		PostQuitMessage(0);
		break;
	}
	return DefWindowProc( hWnd, msg, wParam, lParam );
}

HWND SWindows::CreateWin(	HINSTANCE hInst,
							TCHAR*	szTitleName,
							TCHAR*	szAppName )
{
//	m_hInst = hInst;
	WNDCLASSEX wcex;
	wcex.cbSize			= sizeof( WNDCLASSEX );
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)gMsgProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInst;
	wcex.hIcon			= LoadIcon(hInst, MAKEINTRESOURCE(IDI_APPLICATION));
	wcex.hIconSm		= LoadIcon(hInst, MAKEINTRESOURCE(IDI_APPLICATION));
	wcex.hCursor		= NULL;
	wcex.hbrBackground	= (HBRUSH)GetStockObject(WHITE_BRUSH);
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= szAppName;
	if( !RegisterClassEx(&wcex)) return 0;

	m_hWnd = CreateWindowEx( WS_EX_APPWINDOW, 
							 szAppName,
							 szTitleName,
							 WS_OVERLAPPEDWINDOW,
							 0, 0, 1200, 800,
							 NULL, NULL, hInst, NULL );

	ShowWindow( m_hWnd, SW_SHOW );
	UpdateWindow( m_hWnd );
	return m_hWnd;
}

SWindows::SWindows(void)
{
	g_pWindow = this;
	m_IsActive = FALSE;
}

SWindows::~SWindows(void)
{

}

